package com.aaa.controller;

import com.aaa.dao.UserDao;
import com.aaa.entity.User;

import com.aaa.vo.Result;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class UserController {
    @Autowired
    private UserDao UserDao;
    @PostMapping("add")
    public Result add(User user) {
        UserDao.insert(user);
        return new Result(200, "添加成功", null);
    }

    @GetMapping("list")
    public Result list(Integer current, Integer pageSize) {
        IPage<User> page = new Page<>(current, pageSize);
        UserDao.selectPage(page, null);
        return new Result(200, "查询成功", page);
    }

    @PutMapping("update")
    public Result update(User user) {
        System.out.println(user);
        UserDao.updateById(user);
        return new Result(200, "修改成功", null);
    }

    @DeleteMapping("delete")
    public Result delete(Integer uid) {
        UserDao.deleteById(uid);
        return new Result(200, "删除成功", null);
    }

}
